<?php

	include_once 'Session.class.php';
	include_once 'User.class.php';
	include_once 'Data.class.php';

	class Controller 
	{
		public $session;
		public $route;
		public $user;
		public $view;

		public $db;
		
		public $get;
		public $post;
		public $request;
		
		private function __call($function_name, $params)
		{
			$this->fourohthree();
		}
		
		public function BeforeCall()
		{
			return;
		}
		
		public function AfterCall()
		{
			return;
		}
		
		final public function __construct()
		{	
			global $_ROUTE, $_CONTROLLER_MENU;
		
			$this->route = $_ROUTE;
			$this->session = new Session();
			$this->user = new User();
			$this->view = new View();

			global $_DATASOURCE;
			$this->db = $_DATASOURCE;
			
			$this->get = Data::sanitize($_GET);
			$this->post = Data::sanitize($_POST);
			$this->request = Data::sanitize($_REQUEST);
		
			#Session and User data needs to be available to the view
			$this->view->session = &$this->session;
			$this->view->user = &$this->user;
			
			$this->view->route = $_ROUTE;			
			$this->view->controller_menu = $_CONTROLLER_MENU;
			
			$this->init();
		}
			
		public function init()
		{
			return;
		}
			
		public function redirect($location = false)
		{
			if(!$location)
			{
				return false;
			}
			
			header("Location: $location");
			exit;
		}
	
		#
		#	Errors
		#
		
		final public function fourohthree()
		{
			$this->view->error_message = 'Forbidden on this Server';
			$this->view->DisplayError( 'fourohthree' );
		}	
		
		final public function fourohfour()
		{
			$this->view->error_message = 'Page Not Found';
			$this->view->DisplayError( 'fourohfour' );
		}		
	}
?>